﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace DirectSell.BLL.EFBase
{
    public  class DirectSellDbFactory
    {
        /// <summary>
        /// 创建EF下文对象，已存在就直接取用，不存在就创建并保存起来，保证当前请求内唯一
        /// </summary>
        /// <returns></returns>
        public static DirectSellEntities Create()
        {
            DirectSellEntities dbContext = HttpContext.Current.Items["DirectSellEntities"] as DirectSellEntities;
            if (dbContext == null)
            {
                dbContext = new DirectSellEntities();
                HttpContext.Current.Items["DirectSellEntities"] = dbContext;
            }
            return dbContext;
        }
    }
}
